# Copyright (C) 2006  Apptility LLC  http://www.apptility.com
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA


class OrganizationController < ApplicationController
  scaffold :organization
  $CURRENT_MAIN_TAB_NAME = "Dashboard"
  $CURRENT_SUB_TAB_NAME = "User List"
  
  def not_enterprise_admin
    if current_user.is_enterprise =='y'
      return false
    else
      flash[:notice] = "You do not have enough privileges to access this action. You need[enterprise admin role]." 
      return true
    end    
  end
  
  def edit
    if not_enterprise_admin
      redirect_to :controller => "/user", :action => "home"
    end
    @org = Organization.find(params['id'])
    
  end
  
  def list
    if not_enterprise_admin
      redirect_to :controller => "/user", :action => "home"
    end
    @orgs = Organization.find_all 
    # [paginate :organization, :per_page => 10] 
    @user  =  current_user
    #print "User company id=>"=>@user.company_id
  end
  
  def update
    if not_enterprise_admin
      redirect_to :controller => "/user", :action => "home"
    end

    print  @params['orgId']
    org = Organization.find(params['orgId'])
    org.name = params['orgName']
  
     if org.save
         flash[:simplemsg] = "Company info saved." 
         redirect_to :controller => "/organization", :action => "list"
    end
   end 
   
end
